import { getToken } from '@/utils/auth';

const state = () => ({
  user: {
    token: getToken(),
    userInfo: {}, //用户信息
    // 选科头部省份信息
    provinceData: {},
    // 新选科头部信息
    newSelectSubjectData: {},
    defaultYear: '',
    // 登录弹窗类型
    loginType: '0',
    // 是否是高考版
    isGkb: {},
    phoneData: [],
  },
  indexInfo: {
    appdown: '',
    copyright: '',
    favicon: '',
    logo: '',
    mobile: '',
    title: '',
    wxapp: '',
    wxjiaoliuquan: '',
    vipserviceid: '',
  },
  platformInfo: {},
});

// getters
const getters = {};

// actions
const actions = {
  changeIndexInfo({ commit }, obj) {
    commit('set_indexInfo', obj);
  },
  changePlatformInfo({ commit }, obj) {
    commit('set_platformInfo', obj);
  },
  changePhoneData({ commit }, isGk) {
    commit('set_phone', isGk);
  },

  changeIsGkb({ commit }, isGk) {
    commit('set_isGk', isGk);
  },
  changeXK_TYPE({ commit }, type) {
    commit('set_xktype', type);
  },
  changeYears({ commit }, years) {
    commit('set_years', years);
  },
  changeLoginType({ commit }, type) {
    commit('set_loginType', type);
  },
  changeProvinceData({ commit }, proData) {
    commit('set_provData', proData);
  },
  changeChangeProvinceYear({ commit }, year) {
    commit('set_year', year);
  },
  // 设置用户信息
  changeUserInfo({ commit }, userInfo) {
    commit('set_userInfo', userInfo);
  },
  // 设置token
  changeToken({ commit }, userInfo) {
    commit('set_token', userInfo);
  },
  // 设置用户头像
  changeUserAvatar({ commit }, avatar) {
    commit('set_avatar', avatar);
  },
  // 新选科数据
  changeNewSelectSubjectData({ commit }, subjectData) {
    commit('set_newSelectSubjectData', subjectData);
  },
};

// mutations
const mutations = {
  set_indexInfo: (state, obj) => {
    state.indexInfo = obj;
  },
  set_platformInfo: (state, obj) => {
    state.user.platformInfo = obj;
  },
  set_newSelectSubjectData: (state, subjectData) => {
    state.user.newSelectSubjectData = subjectData;
  },
  set_token: (state, token) => {
    state.user.token = token;
  },
  set_userInfo: (state, useInfo) => {
    state.user.userInfo = useInfo;
  },
  set_provData: (state, proData) => {
    state.user.provinceData = proData;
  },
  set_loginType: (state, type) => {
    state.user.loginType = type;
  },
  set_years: (state, years) => {
    state.user.userInfo.years = years;
  },
  set_xktype: (state, type) => {
    state.user.userInfo.mode = type;
  },
  set_avatar: (state, avatar) => {
    state.user.userInfo.head = avatar;
  },
  set_year: (state, year) => {
    state.user.defaultYear = year;
  },
  set_isGk: (state, isGk) => {
    state.user.isGkb = isGk;
  },
  set_phone: (state, phone) => {
    state.user.phoneData = phone;
  },
};

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations,
};
